﻿using System.Collections.Generic;
using System.Linq;
using Resn.WhuPub.BLL;
using Resn.WhuPub.DAL;
using Resn.WhuPub.DML;
using System;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 获取或设置学校专业招生的属性和方法
        /// </summary>
        public class MajorOperation :Entity<MajorOperationModel>
        {
                /// <summary>
                /// 创建专业招生实例
                /// </summary>
                /// <param name="model">专业招生模型</param>
                public MajorOperation(MajorOperationModel model)
                        : base(model)
                {
                }

                #region 属性

                #region 基本属性

                
                /// <summary>
                /// 获取专业设置标识.
                /// </summary>
                /// <value>
                /// 专业设置标识
                /// </value>
                public string MajorSetupId
                {
                        get
                        {
                                return Model.MajorSetupId;
                        }
                }

                /// <summary>
                /// 获取专业招生的年份
                /// </summary>
                /// <value>
                /// 年份
                /// </value>
                public int Year
                {
                        get
                        {
                                return Model.Year;
                        }
                }

                /// <summary>
                /// 获取或设置专业招生人数
                /// </summary>
                /// <value>
                /// 招生人数
                /// </value>
                public int StudentsAmount
                {
                        get
                        {
                                return Model.StudentsAmount;
                        }
                        set
                        {
                                Model.StudentsAmount = value;
                        }
                }

                #endregion 基本属性

                /// <summary>
                /// 获取专业设置
                /// </summary>
                /// <value>
                /// 专业设置
                /// </value>
                public MajorSetup MajorSetup
                {
                        get
                        {
                                var model = DBStorage.Instance.Select<MajorSetupModel>(MajorSetupId);
                                return new MajorSetup(model);
                        }
                }

                /// <summary>
                /// 获取部门下属开设的专业
                /// </summary>
                /// <value>
                /// 部门下属开设的专业
                /// </value>
                public List<Course> Courses
                {
                        get
                        {
                                var models = DBStorage.Instance.Select<CourseModel>().Where(i => i.MajorOperationId == Id).ToList();

                                var result = new List<Course>();

                                models.ForEach(i => result.Add(new Course(i)));

                                return result;
                        }
                }

                #endregion 属性


                #region 方法

                /// <summary>
                /// 获取指定标识的对象
                /// </summary>
                /// <param name="id">标识</param>
                /// <returns></returns>
                public static MajorOperation Select(string id)
                {
                        return Select<MajorOperation>(id);
                }

                /// <summary>
                /// 创建课程
                /// </summary>
                /// <param name="name">名称</param>
                /// <param name="isCompulsory">是否必修</param>
                /// <param name="studentsAmount">学生人数</param>
                /// <returns>
                /// 创建的课程对象
                /// </returns>
                /// <exception cref="System.NotImplementedException"></exception>
                public Course CreateCourse(string name, bool isCompulsory, int studentsAmount)
                {
                        var model = new CourseModel
                                {
                                        Id = Guid.NewGuid().ToString(),
                                        MajorOperationId = Id,
                                        ContactId = string.Empty,
                                        Name = name,
                                        IsCompulsory = isCompulsory,
                                        StudentsAmount = studentsAmount
                                };
                        return  new Course(model);
                }

                
                #endregion
        }
}